/**
 * Created by losor on 2017/3/10.
 */
public class _459_RepeatedSubstringPattern {
    public static void main(String[] args) {
        String s = "abcabcabcabc";
        _459_RepeatedSubstringPattern ss = new _459_RepeatedSubstringPattern();
        System.out.println(ss.repeatedSubstringPattern(s));
    }

    public boolean repeatedSubstringPattern(String s) {
        StringBuilder sb = new StringBuilder();
        sb.append(s.charAt(0));
        for (int i = 1; i < s.length()/2+1 ; i++) {
            if (checkNumOfString(sb,s)){
                return true;
            }
            else{
                sb.append(s.charAt(i));
            }
        }
        return false;
    }

    public boolean checkNumOfString(StringBuilder stringBuilder, String s){
        if (s.length() % stringBuilder.length() !=0){
            return false;
        }
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) != stringBuilder.charAt(i%stringBuilder.length())){
                return false;
            }
        }
        return true;
    }
}
